rpi3: Enable SDHost driver in BL2
authorYing-Chun Liu (PaulLiu) <[email protected]>
Tue, 29 Jan 2019 20:20:38 +0000 (04:20 +0800)
committerYing-Chun Liu (PaulLiu) <[email protected]>
Thu, 31 Jan 2019 20:09:31 +0000 (04:09 +0800)
This patch inits SDHost in BL2 earlysetup. BL2 can start operating mmc
commands to read/write MMC raw blocks.

Signed-off-by: Ying-Chun Liu (PaulLiu) <[email protected]>
plat/rpi3/include/platform_def.h
plat/rpi3/platform.mk
plat/rpi3/rpi3_bl2_setup.c
plat/rpi3/rpi3_hw.h

index 69ebdb372e0079ae7ab5e359802b44b1d63f615c..4d902225f75a47d0057bf162765d5a6ddd625711 100644 (file)
 #define MAX_IO_DEVICES                 U(3)
 #define MAX_IO_HANDLES                 U(4)
 
+#define MAX_IO_BLOCK_DEVICES           U(1)
+
 /*
  * Serial-related constants.
  */
index ded92bd3db7240ede2095793e060893dd03847c7..ca638d59175ea54c918adc12164c81387b574cb0 100644 (file)
@@ -31,6 +31,9 @@ BL2_SOURCES           +=      common/desc_image_load.c                \
                                drivers/delay_timer/delay_timer.c       \
                                drivers/delay_timer/generic_delay_timer.c \
                                drivers/rpi3/gpio/rpi3_gpio.c           \
+                               drivers/io/io_block.c                   \
+                               drivers/mmc/mmc.c                       \
+                               drivers/rpi3/sdhost/rpi3_sdhost.c       \
                                plat/common/aarch64/platform_mp_stack.S \
                                plat/rpi3/aarch64/plat_helpers.S        \
                                plat/rpi3/aarch64/rpi3_bl2_mem_params_desc.c \
index 09f0562129ab8e610e4a4ffce40c2afdfa206c90..3d1f8f9185c787bc34bce41a8bde4d83f3b59fdd 100644 (file)
@@ -17,6 +17,7 @@
 #include <lib/xlat_tables/xlat_tables_defs.h>
 #include <drivers/generic_delay_timer.h>
 #include <drivers/rpi3/gpio/rpi3_gpio.h>
+#include <drivers/rpi3/sdhost/rpi3_sdhost.h>
 
 #include "rpi3_private.h"
 
@@ -34,6 +35,21 @@ static void rpi3_gpio_setup(void)
        rpi3_gpio_init(&params);
 }
 
+/* Data structure which holds the MMC info */
+static struct mmc_device_info mmc_info;
+
+static void rpi3_sdhost_setup(void)
+{
+       struct rpi3_sdhost_params params;
+
+       memset(&params, 0, sizeof(struct rpi3_sdhost_params));
+       params.reg_base = RPI3_SDHOST_BASE;
+       params.bus_width = MMC_BUS_WIDTH_4;
+       params.clk_rate = 392464;
+       mmc_info.mmc_dev_type = MMC_IS_SD_HC;
+       rpi3_sdhost_init(&params, &mmc_info);
+}
+
 /*******************************************************************************
  * BL1 has passed the extents of the trusted SRAM that should be visible to BL2
  * in x0. This memory layout is sitting at the base of the free trusted SRAM.
@@ -57,6 +73,9 @@ void bl2_early_platform_setup2(u_register_t arg0, u_register_t arg1,
        /* Setup the BL2 memory layout */
        bl2_tzram_layout = *mem_layout;
 
+       /* Setup SDHost driver */
+       rpi3_sdhost_setup();
+
        plat_rpi3_io_setup();
 }
 
@@ -122,6 +141,9 @@ int bl2_plat_handle_post_image_load(unsigned int image_id)
                /* BL33 expects to receive the primary CPU MPID (through r0) */
                bl_mem_params->ep_info.args.arg0 = 0xffff & read_mpidr();
                bl_mem_params->ep_info.spsr = rpi3_get_spsr_for_bl33_entry();
+
+               /* Shutting down the SDHost driver to let BL33 drives SDHost.*/
+               rpi3_sdhost_stop();
                break;
 
        default:
index 61d1837726e40b87a3928ce0af1e5f734572c84b..1a86835b396478b6e00ec2223d6731cfc8bf57b3 100644 (file)
 #define RPI3_IO_GPIO_OFFSET            ULL(0x00200000)
 #define RPI3_GPIO_BASE                 (RPI3_IO_BASE + RPI3_IO_GPIO_OFFSET)
 
+/*
+ * SDHost controller
+ */
+#define RPI3_IO_SDHOST_OFFSET           ULL(0x00202000)
+#define RPI3_SDHOST_BASE                (RPI3_IO_BASE + RPI3_IO_SDHOST_OFFSET)
+
 /*
  * Local interrupt controller
  */